// Includes
#include "CAmbientLight.h"

#ifdef _WIN32
#include <windows.h>		// Include windows header on the windows platform
#endif
#include <GL/gl.h>			// OpenGL header

namespace EraAstral
{
	namespace graphics
	{
		float AmbientLight::accumAmbient[4];	
	
		// Ambient light class constructor
		AmbientLight::AmbientLight(core::SceneManager *sceneManager)
			: ILightSource(sceneManager)
		{
			// Set light type
			m_type = LST_AMBIENT;
			
			// Ambient lights are applied on OpenGL light 7
			m_glLight = GL_LIGHT7;
			
			sceneManager->AddLight(this);
		}
		
		// Ambient light class destructor
		AmbientLight::~AmbientLight()
		{
		}
		
		// Commits light changes to OpenGL
		void AmbientLight::Commit()
		{
			// Commit ambient light component
			glLightfv(m_glLight, GL_AMBIENT, m_color->GetData());
		}
		
		// Applies lighting to the current scene
		void AmbientLight::Apply()
		{
			if (m_enabled)
				// Accumulate ambient lighting
				for (int i = 0; i < 4; i++)
					accumAmbient[i] += m_color->GetData()[i];
		}
		
		// Gets the accumulated ambient values
		float *AmbientLight::GetAccumAmbient()
		{
			return AmbientLight::accumAmbient;
		}
		
		// Clears the accumulated ambient values
		void AmbientLight::ClearAccumAmbient()
		{
			for (int i = 0; i < 4; i++)
				AmbientLight::accumAmbient[i] = 0.0f;
		}
	}
}
